﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Controls_SPLink : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Top = "4";
        Init_Link();
    }
    private string _top;
    public string Top
    {
        set { _top = value; }
        get { return _top; }
    }
    private string _html;
    public string HTML
    {
        set { _html = value; }
        get { return _html; }
    }
    private void Init_Link()
    {
        if (Request.QueryString["PID"] != null)
        {
            StringBuilder Sb = new StringBuilder();
            string product = Request.QueryString["PID"].ToString();
            BLL.COMMODITY_LINK bll_link = new BLL.COMMODITY_LINK();
            DataTable dt = bll_link.GetTopList(product, Top);
            if (dt.Rows.Count > 0)
            {
                Sb.Append("<div class=\"r_title\">");
                Sb.Append("<h2>关联产品</h2>");
                Sb.Append("</div>");
                Sb.Append("<ul>");
                foreach (DataRow row in dt.Rows)
                {
                    Sb.Append("<li class=\"r_chanpin\">");
                    Sb.Append("<a href=\"P_" + row["SPDM"].ToString() + "_" + row["CP_COLOR"].ToString() + ".html\">");
                    Sb.Append("<img src=\"" + BLL.Common.GetProductPicPath("com") + BLL.Common.GetPath(row["CP_PICPATH"].ToString()) + row["CP_PICPATH"].ToString() + "\" /></a>");
                    Sb.Append("<dl>");
                    Sb.Append("<dt>");
                    Sb.Append("<a href=\"P_" + row["SPDM"].ToString() + "_" + row["CP_COLOR"].ToString() + ".html\">");
                    Sb.Append(row["SPMC"].ToString());
                    Sb.Append("<br/></a></dt>");
                    Sb.Append("<dd>吊牌价：" + string.Format("{0:F}",row[BasePage.GetSJ()]) + "</dd>");
                    Sb.Append("<dd><em><span>会员价:</span></em>");
                    if (HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        decimal price = decimal.Parse(row[BasePage.GetSJ()].ToString());
                        decimal zk = decimal.Parse(BasePage.GetValue(1));
                        decimal memberprice = price * zk;
                        Sb.Append("<em><span>" + memberprice.ToString("F") + "</span></em></dd>");
                    }
                    else
                    {
                        Sb.Append("<a href=\"../Users/Login.aspx\">请登陆</a></dd>");
                    }
                    Sb.Append("</dl>");
                }
                Sb.Append("</ul>");
                HTML = Sb.ToString();
            }
        }
    }
}
